package com.pets.springboot_petshop.mapper;

import com.pets.springboot_petshop.entity.Order;
import com.pets.springboot_petshop.entity.Orderproduct;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: wxk
 * @Email: 2089967794@qq.com
 * @Date: 2024/10/15 下午2:37 周二
 * @Description: 订单详情访问层接口
 */
@Mapper
@Repository
public interface OrderproductMapper {
    //order_id查询
    @Select("SELECT " +
            "a.id, " +
            "a.order_id, " +
            "a.quantity, " +
            "a.discount_price, " +
            "a.product_id, " +
            "a.original_price, " +
            "c.img, " +
            "c.name " +
            "FROM `orderproduct` a " +
            "JOIN `order` b ON a.order_id = b.id " +
            "JOIN product c ON a.product_id = c.id " +
            "WHERE a.order_id = #{order_id}")
    List<Orderproduct> selectorder_id(int order_id);
    //查询所有
    @Select("SELECT " +
            "a.id, " +
            "a.order_id, " +
            "a.quantity, " +
            "a.discount_price, " +
            "a.original_price, " +
            "a.product_id, " +
            "c.name " +
            "FROM `orderproduct` a " +
            "JOIN `order` b ON a.order_id = b.id " +
            "JOIN product c ON a.product_id = c.id ")
    List<Orderproduct> findAll();
    //添加
    @Insert("insert into `orderproduct`(order_id,quantity,product_id,discount_price,original_price)values(#{order_id},#{quantity},#{product_id},#{discount_price},#{original_price});")
    int add(Orderproduct orderproduct);
    //删除
    @Delete("delete from `orderproduct` where id=#{id};")
    int delete(int id);
    //修改数据
    @Update("UPDATE `orderproduct` SET order_id=#{order_id},quantity=#{quantity},product_id=#{product_id},discount_price=#{discount_price},original_price=#{original_price} where id= #{id};")
    int update(Orderproduct orderproduct);

}
